package com.api.phm.controller;

import com.alibaba.fastjson2.JSONObject;
import com.api.common.core.controller.BaseController;
import com.api.common.core.domain.AjaxResult;
import com.api.common.core.page.TableDataInfo;
import com.api.common.utils.MessageUtils;
import com.api.phm.domain.vo.FaultLogVo;
import com.api.phm.service.IFaultLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/hscn/alarm/log")
public class FaultLogController extends BaseController {
    @Autowired
    private IFaultLogService faultLogService;

    @PostMapping("/list")
    public TableDataInfo searchFaultLogList(@RequestBody FaultLogVo faultLogVo
            , @RequestHeader("App-Language") String appLang) throws Exception {
        startPageByPost(faultLogVo.getPageNum(), faultLogVo.getPageSize());
        faultLogVo.setAppLang(appLang);
//        List<FaultLogPageQuery> list = faultLogService.searchFaultLogList(faultLogVo);
//        return getDataTable(list);
        return getDataTable(faultLogService.searchFaultLogList(faultLogVo));
    }

    @PostMapping("/read")
    public AjaxResult read(@RequestBody JSONObject jo
            , @RequestHeader("App-Language") String appLang) {
        if (!jo.containsKey("faultId"))
            return AjaxResult.error(MessageUtils.message(appLang, "faultLog.noId"));
        try {
            String faultId = jo.getString("faultId");
            AjaxResult ajaxResult = AjaxResult.success();
            faultLogService.readFaultLogMessage(faultId);
            ajaxResult.put("message", MessageUtils.message(appLang, "faultLog.read.success"));
            return ajaxResult;
        } catch (Exception e) {
            return AjaxResult.error(MessageUtils.message(appLang, "faultLog.read.error"));
        }
    }
}
